// Package pay_api provides constants for payment API operations.
package pay_api

// API endpoints
const (
	// Base URL
	DefaultBaseURL = "https://pay.space-iot.net/api/grpcProxy/"

	// Order endpoints
	OrderCreateEndpoint = "pay.OrderService/create"
	OrderQueryEndpoint  = "pay.OrderService/query"
	OrderRefundEndpoint = "pay.OrderService/refund"

	// Agent endpoints
	AgentCreateEndpoint = "pay.AgentService/create"
	AgentUpdateEndpoint = "pay.AgentService/update"
	AgentGetEndpoint    = "pay.AgentService/get"

	// PayChannel endpoints
	PayChannelCreateEndpoint = "pay.PayChannelService/create"
	PayChannelUpdateEndpoint = "pay.PayChannelService/update"
	PayChannelGetEndpoint    = "pay.PayChannelService/get"
	PayChannelDeleteEndpoint = "pay.PayChannelService/delete"
)

// Payment methods
const (
	PayWayCash   = "CASH"   // CASH-现金
	PayWayWXZF   = "WXZF"   // WXZF-微信
	PayWayZFBZF  = "ZFBZF"  // ZFBZF-支付宝
	PayWayUPSMZF = "UPSMZF" // UPSMZF-银联二维码
)

// JSPay flags
const (
	JspayFlag0 = "0" // 0-支付宝Native扫码支付、银联Native扫码支付
	JspayFlag1 = "1" // 1-微信JSAPI、支付宝JSAPI支付、银联JSAPI支付
	JspayFlag2 = "2" // 2-微信、支付宝简易支付<跳转乐刷收银台支付>（jspay_flag=2时必传jump_url，否则会报错）
	JspayFlag3 = "3" // 3-微信小程序支付、支付宝小程序支付
)

// Payment types
const (
	WXZF    = "WXZF"    // 微信支付
	ZFBZF   = "ZFBZF"   // 支付宝支付
	UPSMZF  = "UPSMZF"  // 银联二维码支付
	QQZF    = "QQZF"    // QQ支付
	POS     = "POS"     // 刷卡支付
	DCPAY   = "DCPAY"   // 数字货币支付
	UPSMPAY = "UPSMPAY" // 银联二维码(回调时返回)支付

	Supported    = "支持"  // 支持状态
	NotSupported = "不支持" // 不支持状态
)

// PaymentType represents payment type information
type PaymentType struct {
	Code   string // 支付类型代码
	Name   string // 支付类型名称
	Status string // 是否支持
}

// PaymentTypes creates payment type mapping
var PaymentTypes = map[string]PaymentType{
	WXZF:    {Code: WXZF, Name: "微信支付", Status: Supported},
	ZFBZF:   {Code: ZFBZF, Name: "支付宝支付", Status: Supported},
	UPSMZF:  {Code: UPSMZF, Name: "银联二维码支付", Status: Supported},
	QQZF:    {Code: QQZF, Name: "QQ支付", Status: Supported},
	POS:     {Code: POS, Name: "刷卡支付", Status: Supported},
	DCPAY:   {Code: DCPAY, Name: "数字货币支付", Status: Supported},
	UPSMPAY: {Code: UPSMPAY, Name: "银联二维码(回调时返回)支付", Status: Supported},
}

// GetPaymentTypesMessage returns payment type message
func GetPaymentTypesMessage(code string) (string, error) {
	message, exists := PaymentTypes[code]
	if !exists {
		return "未知类型", nil
	}
	return message.Name, nil
}

// PayChannel represents payment channel type
type PayChannel int

const (
	PayChannelWX              PayChannel = iota + 1 // 微信
	PayChannelZFB                                   // 支付宝
	PayChannelUnionPay                              // 银联
	PayChannelDigitalCurrency                       // 数字货币
	PayChannelQQ                                    // QQ
	PayChannelCard                                  // 刷卡
	PayChannelLeShua                                // 乐刷
	PayChannelWXSCAN                                // 微信小程序
	PayChannelWXApp                                 // 微信扫码支付
	PayChannelWXPC                                  // 微信PC支付
	PayChannelJsb                                   // 江苏银行
)

// PayChannelMap maps payment channels to their descriptions
var PayChannelMap = map[PayChannel]string{
	PayChannelWX:              "微信",
	PayChannelZFB:             "支付宝",
	PayChannelUnionPay:        "银联",
	PayChannelDigitalCurrency: "数字货币",
	PayChannelQQ:              "QQ",
	PayChannelCard:            "刷卡",
	PayChannelLeShua:          "乐刷",
	PayChannelWXSCAN:          "微信小程序",
	PayChannelWXApp:           "微信扫码支付（商户扫用户付款码）",
	PayChannelWXPC:            "微信PC支付",
	PayChannelJsb:             "江苏银行",
}

// GetPayChannelMessage returns payment channel message
func GetPayChannelMessage(channel PayChannel) string {
	if message, exists := PayChannelMap[channel]; exists {
		return message
	}
	return "未知支付渠道"
}

// PayStatus represents payment status
type PayStatus int

const (
	StatusPending  PayStatus = 1 + iota // 待支付
	StatusPaying   PayStatus = 2         // 支付中
	StatusPaid     PayStatus = 3         // 已支付
	StatusCancel   PayStatus = 4         // 已取消
	StatusRefunded PayStatus = 5         // 已退款
)

// statusMessages maps payment status to their descriptions
var statusMessages = map[PayStatus]string{
	StatusPending:  "待支付",
	StatusPaying:   "支付中",
	StatusPaid:     "已支付",
	StatusCancel:   "已取消",
	StatusRefunded: "已退款",
}

// GetStatusMessage returns status message
func GetStatusMessage(status PayStatus) string {
	message, exists := statusMessages[status]
	if !exists {
		return "未知状态"
	}
	return message
}